# ------------------------------------------------------------------------------
Qthreshold <- 0.10
# ------------------------------------------------------------------------------
# C only calibration
# ------------------------------------------------------------------------------
# The data is loaded
load(dir_C)
C <- as.data.frame(t(outputForSeries$Ctot))
d13C <- as.data.frame(t(outputForSeries$d13C))
d14C <- as.data.frame(t(outputForSeries$d14C))
depth <- outputForSeries$midDepth
error <- as.data.frame(outputForSeries$error)
names(error) <- "error"
relError_OC_POC <- as.data.frame(outputForSeries$relError_OC_POC)
names(relError_OC_POC) <- "relError_OC_POC"
relError_OC_MAOC <- as.data.frame(outputForSeries$relError_OC_MAOC)
names(relError_OC_MAOC) <- "relError_OC_MAOC"
relError_d13C_POC <- as.data.frame(outputForSeries$relError_d13C_POC)
names(relError_d13C_POC) <- "relError_d13C_POC"
relError_d13C_MAOC <- as.data.frame(outputForSeries$relError_d13C_MAOC)
names(relError_d13C_MAOC) <- "relError_d13C_MAOC"
relError_d14C_POC <- as.data.frame(outputForSeries$relError_d14C_POC)
names(relError_d14C_POC) <- "relError_d14C_POC"
relError_d14C_MAOC <- as.data.frame(outputForSeries$relError_d14C_MAOC)
names(relError_d14C_MAOC) <- "relError_d14C_MAOC"
POC_perc <- as.data.frame(t(outputForSeries$POC_perc))
bulkOC_perc <- as.data.frame(t(outputForSeries$bulkOC_perc))
# The distribution of the errors is plotted
e1 <- ggplot(error, aes(error)) +
geom_histogram(binwidth = 0.1) +
scale_x_continuous(limits = c(0,50)) +
scale_y_continuous(limits = c(0,1000))
# The X % lowest errors are retained
q_C <- quantile(error$error,Qthreshold) # The error value which marks the Qthreshold
n <- which(error > q_C) # The rows with errors larger than this quantile
C <- subset(C,select = -n)
d13C <- subset(d13C,select = -n)
d14C <- subset(d14C,select = -n)
error_opt <- error[-n,1]
# The errors for the different evaluated criteria
error_OC_POC_opt <- relError_OC_POC[-n,1]
error_OC_MAOC_opt <- relError_OC_MAOC[-n,1]
error_d13C_POC_opt <- relError_d13C_POC[-n,1]
error_d13C_MAOC_opt <- relError_d13C_MAOC[-n,1]
error_d14C_POC_opt <- relError_d14C_POC[-n,1]
error_d14C_MAOC_opt <- relError_d14C_MAOC[-n,1]
# # The average errors for OC, d13C and d14C
avgError_OC_Conly <- mean(error_OC_POC_opt) + mean(error_OC_MAOC_opt)
avgError_d13C_Conly <- mean(error_d13C_POC_opt) + mean(error_d13C_MAOC_opt)
avgError_d14C_Conly <- mean(error_d14C_POC_opt) + mean(error_d14C_MAOC_opt)
totalError_Conly <- sum(avgError_OC_Conly + avgError_d13C_Conly + avgError_d14C_Conly)
# The errors per run are weighted based on the simulated amounts of POC and bulkOC
indErrors_OC_Conly <- ((POC_perc_tot * error_OC_POC_opt) + (bulkOC_perc_tot * error_OC_MAOC_opt)) / (POC_perc_tot + bulkOC_perc_tot)
indErrors_d13C_Conly <- ((POC_perc_tot * error_d13C_POC_opt) + (bulkOC_perc_tot * error_d13C_MAOC_opt)) / (POC_perc_tot + bulkOC_perc_tot)
indErrors_d14C_Conly <- ((POC_perc_tot * error_d14C_POC_opt) + (bulkOC_perc_tot * error_d14C_MAOC_opt)) / (POC_perc_tot + bulkOC_perc_tot)
# The average errors are calculated
avgError_OC_Conly <- mean(indErrors_OC_Conly)
rm(list=ls(all = TRUE))
cat("\014")
library("ggplot2")
library("reshape2")
library("gridExtra")
library("readxl")
library("corrplot")
library("RColorBrewer")
library("gridGraphics")
library("grid")
library("dplyr")
library("scales")
library("ggpubr")
library("GGally")
library("patchwork")
source("f_createClasses.R")
source("f_load_measured_data.R")
# ---------------------------
# The measured data is loaded
# ---------------------------
createInputClass()
par <- new("inputObject")
par@evalDepth <- .7
out <- loadMeasuredData("Hainich")
measuredData_soil <- out$measuredData_soil
rm(out)
# ------------------------------------------
# The locations of the data files to be used
# -----------------------------------------
# These files contain the model output for *all* parameter combinations
# that have been tested by the DE algorithm
dir_C <- "Analysis DE output/outputForSeries_C.RData"
dir_C_d13C <- "Analysis DE output/outputForSeries_C_d13C.RData"
dir_C_d14C <- "Analysis DE output/outputForSeries_C_d14C.RData"
dir_C_d13C_d14C <- "Analysis DE output/outputForSeries_C_d13C_d14C.RData"
# ------------------------------------------------------------------------------
# Defining the fraction of best runs to be retained
# ------------------------------------------------------------------------------
Qthreshold <- 0.10
# ------------------------------------------------------------------------------
# C only calibration
# ------------------------------------------------------------------------------
# The data is loaded
load(dir_C)
C <- as.data.frame(t(outputForSeries$Ctot))
d13C <- as.data.frame(t(outputForSeries$d13C))
d14C <- as.data.frame(t(outputForSeries$d14C))
depth <- outputForSeries$midDepth
error <- as.data.frame(outputForSeries$error)
names(error) <- "error"
relError_OC_POC <- as.data.frame(outputForSeries$relError_OC_POC)
names(relError_OC_POC) <- "relError_OC_POC"
relError_OC_MAOC <- as.data.frame(outputForSeries$relError_OC_MAOC)
names(relError_OC_MAOC) <- "relError_OC_MAOC"
relError_d13C_POC <- as.data.frame(outputForSeries$relError_d13C_POC)
names(relError_d13C_POC) <- "relError_d13C_POC"
relError_d13C_MAOC <- as.data.frame(outputForSeries$relError_d13C_MAOC)
names(relError_d13C_MAOC) <- "relError_d13C_MAOC"
relError_d14C_POC <- as.data.frame(outputForSeries$relError_d14C_POC)
names(relError_d14C_POC) <- "relError_d14C_POC"
relError_d14C_MAOC <- as.data.frame(outputForSeries$relError_d14C_MAOC)
names(relError_d14C_MAOC) <- "relError_d14C_MAOC"
POC_perc <- as.data.frame(t(outputForSeries$POC_perc))
# This script is used to analyse the C profiles generated by the Differential Evolution algorithm
rm(list=ls(all = TRUE))
cat("\014")
library("ggplot2")
library("reshape2")
library("gridExtra")
library("readxl")
library("corrplot")
library("RColorBrewer")
library("gridGraphics")
library("grid")
library("dplyr")
library("scales")
library("ggpubr")
library("GGally")
library("patchwork")
source("f_createClasses.R")
source("f_load_measured_data.R")
# ---------------------------
# The measured data is loaded
# ---------------------------
createInputClass()
par <- new("inputObject")
par@evalDepth <- .7
out <- loadMeasuredData("Hainich")
measuredData_soil <- out$measuredData_soil
rm(out)
# ------------------------------------------
# The locations of the data files to be used
# -----------------------------------------
# These files contain the model output for *all* parameter combinations
# that have been tested by the DE algorithm
dir_C <- "Analysis DE output/outputForSeries_C.RData"
dir_C_d13C <- "Analysis DE output/outputForSeries_C_d13C.RData"
dir_C_d14C <- "Analysis DE output/outputForSeries_C_d14C.RData"
dir_C_d13C_d14C <- "Analysis DE output/outputForSeries_C_d13C_d14C.RData"
# ------------------------------------------------------------------------------
# Defining the fraction of best runs to be retained
# ------------------------------------------------------------------------------
Qthreshold <- 0.10
# ------------------------------------------------------------------------------
# C only calibration
# ------------------------------------------------------------------------------
# The data is loaded
load(dir_C)
C <- as.data.frame(t(outputForSeries$Ctot))
d13C <- as.data.frame(t(outputForSeries$d13C))
d14C <- as.data.frame(t(outputForSeries$d14C))
depth <- outputForSeries$midDepth
error <- as.data.frame(outputForSeries$error)
names(error) <- "error"
relError_OC_POC <- as.data.frame(outputForSeries$relError_OC_POC)
names(relError_OC_POC) <- "relError_OC_POC"
relError_OC_MAOC <- as.data.frame(outputForSeries$relError_OC_MAOC)
names(relError_OC_MAOC) <- "relError_OC_MAOC"
relError_d13C_POC <- as.data.frame(outputForSeries$relError_d13C_POC)
names(relError_d13C_POC) <- "relError_d13C_POC"
relError_d13C_MAOC <- as.data.frame(outputForSeries$relError_d13C_MAOC)
names(relError_d13C_MAOC) <- "relError_d13C_MAOC"
relError_d14C_POC <- as.data.frame(outputForSeries$relError_d14C_POC)
names(relError_d14C_POC) <- "relError_d14C_POC"
relError_d14C_MAOC <- as.data.frame(outputForSeries$relError_d14C_MAOC)
names(relError_d14C_MAOC) <- "relError_d14C_MAOC"
POC_perc <- as.data.frame(t(outputForSeries$POC_perc))
# The distribution of the errors is plotted
e1 <- ggplot(error, aes(error)) +
geom_histogram(binwidth = 0.1) +
scale_x_continuous(limits = c(0,50)) +
scale_y_continuous(limits = c(0,1000))
# The X % lowest errors are retained
q_C <- quantile(error$error,Qthreshold) # The error value which marks the Qthreshold
n <- which(error > q_C) # The rows with errors larger than this quantile
C <- subset(C,select = -n)
d13C <- subset(d13C,select = -n)
d14C <- subset(d14C,select = -n)
error_opt <- error[-n,1]
# The errors for the different evaluated criteria
error_OC_POC_opt <- relError_OC_POC[-n,1]
error_OC_MAOC_opt <- relError_OC_MAOC[-n,1]
error_d13C_POC_opt <- relError_d13C_POC[-n,1]
error_d13C_MAOC_opt <- relError_d13C_MAOC[-n,1]
error_d14C_POC_opt <- relError_d14C_POC[-n,1]
error_d14C_MAOC_opt <- relError_d14C_MAOC[-n,1]
# # The average errors for OC, d13C and d14C
avgError_OC_Conly <- mean(error_OC_POC_opt) + mean(error_OC_MAOC_opt)
# # The average errors for OC, d13C and d14C
avgError_OC_Conly <- mean(error_OC_POC_opt) + mean(error_OC_MAOC_opt)
avgError_d13C_Conly <- mean(error_d13C_POC_opt) + mean(error_d13C_MAOC_opt)
avgError_d14C_Conly <- mean(error_d14C_POC_opt) + mean(error_d14C_MAOC_opt)
totalError_Conly <- sum(avgError_OC_Conly + avgError_d13C_Conly + avgError_d14C_Conly)
# The errors per run are weighted based on the simulated amounts of POC and bulkOC
indErrors_OC_Conly <- ((POC_perc_tot * error_OC_POC_opt) + (bulkOC_perc_tot * error_OC_MAOC_opt)) / (POC_perc_tot + bulkOC_perc_tot)
# This script is used to analyse the C profiles generated by the Differential Evolution algorithm
rm(list=ls(all = TRUE))
cat("\014")
library("ggplot2")
library("reshape2")
library("gridExtra")
library("readxl")
library("corrplot")
library("RColorBrewer")
library("gridGraphics")
library("grid")
library("dplyr")
library("scales")
library("ggpubr")
library("GGally")
library("patchwork")
source("f_createClasses.R")
source("f_load_measured_data.R")
# ---------------------------
# The measured data is loaded
# ---------------------------
createInputClass()
par <- new("inputObject")
par@evalDepth <- .7
out <- loadMeasuredData("Hainich")
measuredData_soil <- out$measuredData_soil
rm(out)
# ------------------------------------------
# The locations of the data files to be used
# -----------------------------------------
# These files contain the model output for *all* parameter combinations
# that have been tested by the DE algorithm
dir_C <- "Analysis DE output/outputForSeries_C.RData"
dir_C_d13C <- "Analysis DE output/outputForSeries_C_d13C.RData"
dir_C_d14C <- "Analysis DE output/outputForSeries_C_d14C.RData"
dir_C_d13C_d14C <- "Analysis DE output/outputForSeries_C_d13C_d14C.RData"
# ------------------------------------------------------------------------------
# Defining the fraction of best runs to be retained
# ------------------------------------------------------------------------------
Qthreshold <- 0.10
# ------------------------------------------------------------------------------
# C only calibration
# ------------------------------------------------------------------------------
# The data is loaded
load(dir_C)
C <- as.data.frame(t(outputForSeries$Ctot))
d13C <- as.data.frame(t(outputForSeries$d13C))
d14C <- as.data.frame(t(outputForSeries$d14C))
depth <- outputForSeries$midDepth
error <- as.data.frame(outputForSeries$error)
names(error) <- "error"
relError_OC_POC <- as.data.frame(outputForSeries$relError_OC_POC)
names(relError_OC_POC) <- "relError_OC_POC"
relError_OC_MAOC <- as.data.frame(outputForSeries$relError_OC_MAOC)
names(relError_OC_MAOC) <- "relError_OC_MAOC"
relError_d13C_POC <- as.data.frame(outputForSeries$relError_d13C_POC)
names(relError_d13C_POC) <- "relError_d13C_POC"
relError_d13C_MAOC <- as.data.frame(outputForSeries$relError_d13C_MAOC)
names(relError_d13C_MAOC) <- "relError_d13C_MAOC"
relError_d14C_POC <- as.data.frame(outputForSeries$relError_d14C_POC)
names(relError_d14C_POC) <- "relError_d14C_POC"
relError_d14C_MAOC <- as.data.frame(outputForSeries$relError_d14C_MAOC)
names(relError_d14C_MAOC) <- "relError_d14C_MAOC"
View(outputForSeries)
View(outputForSeries)
# This script is used to analyse the C profiles generated by the Differential Evolution algorithm
rm(list=ls(all = TRUE))
cat("\014")
library("ggplot2")
library("reshape2")
library("gridExtra")
library("readxl")
library("corrplot")
library("RColorBrewer")
library("gridGraphics")
library("grid")
library("dplyr")
library("scales")
library("ggpubr")
library("GGally")
library("patchwork")
source("f_createClasses.R")
source("f_load_measured_data.R")
# ---------------------------
# The measured data is loaded
# ---------------------------
createInputClass()
par <- new("inputObject")
par@evalDepth <- .7
out <- loadMeasuredData("Hainich")
measuredData_soil <- out$measuredData_soil
rm(out)
# ------------------------------------------
# The locations of the data files to be used
# -----------------------------------------
# These files contain the model output for *all* parameter combinations
# that have been tested by the DE algorithm
dir_C <- "Analysis DE output/outputForSeries_C.RData"
dir_C_d13C <- "Analysis DE output/outputForSeries_C_d13C.RData"
dir_C_d14C <- "Analysis DE output/outputForSeries_C_d14C.RData"
dir_C_d13C_d14C <- "Analysis DE output/outputForSeries_C_d13C_d14C.RData"
Qthreshold <- 0.10
# The data is loaded
load(dir_C)
C <- as.data.frame(t(outputForSeries$Ctot))
d13C <- as.data.frame(t(outputForSeries$d13C))
d14C <- as.data.frame(t(outputForSeries$d14C))
depth <- outputForSeries$midDepth
error <- as.data.frame(outputForSeries$error)
names(error) <- "error"
relError_OC_POC <- as.data.frame(outputForSeries$relError_OC_POC)
names(relError_OC_POC) <- "relError_OC_POC"
relError_OC_MAOC <- as.data.frame(outputForSeries$relError_OC_MAOC)
names(relError_OC_MAOC) <- "relError_OC_MAOC"
relError_d13C_POC <- as.data.frame(outputForSeries$relError_d13C_POC)
names(relError_d13C_POC) <- "relError_d13C_POC"
relError_d13C_MAOC <- as.data.frame(outputForSeries$relError_d13C_MAOC)
names(relError_d13C_MAOC) <- "relError_d13C_MAOC"
relError_d14C_POC <- as.data.frame(outputForSeries$relError_d14C_POC)
names(relError_d14C_POC) <- "relError_d14C_POC"
relError_d14C_MAOC <- as.data.frame(outputForSeries$relError_d14C_MAOC)
names(relError_d14C_MAOC) <- "relError_d14C_MAOC"
POC_perc <- as.data.frame(t(outputForSeries$POC_perc))
bulkOC_perc <- as.data.frame(t(outputForSeries$bulkOC_perc))
# The distribution of the errors is plotted
e1 <- ggplot(error, aes(error)) +
geom_histogram(binwidth = 0.1) +
scale_x_continuous(limits = c(0,50)) +
scale_y_continuous(limits = c(0,1000))
# The X % lowest errors are retained
q_C <- quantile(error$error,Qthreshold) # The error value which marks the Qthreshold
n <- which(error > q_C) # The rows with errors larger than this quantile
C <- subset(C,select = -n)
d13C <- subset(d13C,select = -n)
d14C <- subset(d14C,select = -n)
error_opt <- error[-n,1]
# The errors for the different evaluated criteria
error_OC_POC_opt <- relError_OC_POC[-n,1]
error_OC_MAOC_opt <- relError_OC_MAOC[-n,1]
error_d13C_POC_opt <- relError_d13C_POC[-n,1]
error_d13C_MAOC_opt <- relError_d13C_MAOC[-n,1]
error_d14C_POC_opt <- relError_d14C_POC[-n,1]
error_d14C_MAOC_opt <- relError_d14C_MAOC[-n,1]
POC_perc <- subset(POC_perc,select = -n)
bulkOC_perc <- subset(bulkOC_perc,select = -n)
# # The total amounts of POC and bulkOC are calcultaed
POC_perc_tot <- unname(colSums(POC_perc))
bulkOC_perc_tot <- unname(colSums(bulkOC_perc))
# # The average errors for OC, d13C and d14C
avgError_OC_Conly <- mean(error_OC_POC_opt) + mean(error_OC_MAOC_opt)
avgError_d13C_Conly <- mean(error_d13C_POC_opt) + mean(error_d13C_MAOC_opt)
avgError_d14C_Conly <- mean(error_d14C_POC_opt) + mean(error_d14C_MAOC_opt)
totalError_Conly <- sum(avgError_OC_Conly + avgError_d13C_Conly + avgError_d14C_Conly)
# The errors per run are weighted based on the simulated amounts of POC and bulkOC
indErrors_OC_Conly <- ((POC_perc_tot * error_OC_POC_opt) + (bulkOC_perc_tot * error_OC_MAOC_opt)) / (POC_perc_tot + bulkOC_perc_tot)
indErrors_d13C_Conly <- ((POC_perc_tot * error_d13C_POC_opt) + (bulkOC_perc_tot * error_d13C_MAOC_opt)) / (POC_perc_tot + bulkOC_perc_tot)
indErrors_d14C_Conly <- ((POC_perc_tot * error_d14C_POC_opt) + (bulkOC_perc_tot * error_d14C_MAOC_opt)) / (POC_perc_tot + bulkOC_perc_tot)
# The average errors are calculated
avgError_OC_Conly <- mean(indErrors_OC_Conly)
avgError_d13C_Conly <- mean(indErrors_d13C_Conly)
avgError_d14C_Conly <- mean(indErrors_d14C_Conly)
totalError_Conly <- avgError_OC_Conly + avgError_d13C_Conly + avgError_d14C_Conly
# Q1 and Q3 are calculated
Q.OC.Conly <- c(summary(indErrors_OC_Conly)[["1st Qu."]], summary(indErrors_OC_Conly)[["3rd Qu."]])
Q.d13C.Conly <- c(summary(indErrors_d13C_Conly)[["1st Qu."]], summary(indErrors_d13C_Conly)[["3rd Qu."]])
Q.d14C.Conly <- c(summary(indErrors_d14C_Conly)[["1st Qu."]], summary(indErrors_d14C_Conly)[["3rd Qu."]])
# The average C, d13C and d14C depth profiles are calculated
df_avg <- data.frame(depth = depth,
avg_C = rowMeans(C,na.rm = T),
avg_d13C = rowMeans(d13C,na.rm = T),
avg_d14C = rowMeans(d14C,na.rm = T))
# The optimal profiles are stored
rowNum_opt <- which(error_opt == min(error_opt))
df_opt <- data.frame("depth" = depth,
"opt_C" = C[,rowNum_opt],
"opt_d13C" = d13C[,rowNum_opt],
"opt_d14C" = d14C[,rowNum_opt])
# The depth is added to the data frames
C$depth = depth
d13C$depth = depth
d14C$depth = depth
# The data frames are reformatted for plotting
df_C <- melt(C, id.vars = "depth")
df_d13C <- melt(d13C, id.vars = "depth")
df_d14C <- melt(d14C, id.vars = "depth")
# A function to plot the C depth profiles
plot_C <- function(df_C, df_avg, df_opt, measuredData_soil, color_lines, color_avg, par){
p <- ggplot(df_C, aes(x = value, y = depth, colour = variable)) +
geom_path() +
scale_y_continuous(expand = c(0,0), trans = "reverse", sec.axis = sec_axis(~ ., labels = NULL)) +
scale_x_continuous(expand = c(0,0), position = "top", sec.axis = sec_axis(~ ., labels = NULL)) +
scale_colour_manual(labels = unique(df_C$variable),
values = rep(color_lines,length(unique(df_C$variable)))) +
coord_cartesian(xlim = c(0, 10), ylim = c(df_avg$depth[9], 0)) +
geom_path(data = df_avg, aes(x = avg_C, y = depth), size = 2, colour = color_avg) +
# geom_path(data = df_opt, aes(x = opt_C, y = depth), size = 1, colour = "black", linetype = "dotted") +
geom_point(data = measuredData_soil, aes(x = fPOC_conc + MAOC_conc, y = Depth), color = "black") +
geom_errorbarh(data = measuredData_soil, aes(y = Depth, xmin = (fPOC_conc +  MAOC_conc) - sqrt(fPOC_conc_stDev^2 + MAOC_conc_stDev^2), xmax = (fPOC_conc +  MAOC_conc) + sqrt(fPOC_conc_stDev^2 + MAOC_conc_stDev^2), height = .01), color = "black", inherit.aes = FALSE) +
theme_classic() +
theme(legend.position = "none",
panel.border = element_rect(color = "black",
fill = NA,
size = 1),
# axis.line = element_line(colour = "black",
#                          size = 0),
axis.text=element_text(size = 16),
axis.title=element_text(size = 16),
plot.margin = margin(0, 5, 0, 0, "mm")) + # #top, right, bottom, left
labs(x = "C (%)")
return(p)
}
# A function to plot the d13C depth profiles
plot_d13C <- function(df_d13C, df_avg, df_opt, measuredData_soil, color_lines, color_avg, par){
p <- ggplot(df_d13C, aes(x = value, y = depth, colour = variable)) +
geom_path() +
scale_y_continuous(expand = c(0,0), trans = "reverse", sec.axis = sec_axis(~ ., labels = NULL)) +
scale_x_continuous(expand = c(0,0), position = "top", sec.axis = sec_axis(~ ., labels = NULL)) +
scale_colour_manual(labels = unique(df_C$variable),
values = rep(color_lines,length(unique(df_C$variable)))) +
coord_cartesian(xlim = c(-28, -24), ylim = c(df_avg$depth[9], 0)) +
geom_path(data = df_avg, aes(x = avg_d13C, y = depth), size = 2, colour = color_avg) +
geom_point(data = measuredData_soil, aes(x = total_d13C, y = Depth), color = "black") +
# geom_path(data = df_opt, aes(x = opt_d13C, y = depth), size = 2, colour = "black", linetype = "dotted") +
geom_errorbarh(data = measuredData_soil, aes(y = Depth, xmin = ((fPOC_d13C*fPOC_conc +  MAOC_d13C*MAOC_conc)/(fPOC_conc +  MAOC_conc)) - sqrt(fPOC_d13C_stDev^2 + MAOC_d13C_stDev^2), xmax = ((fPOC_d13C*fPOC_conc +  MAOC_d13C*MAOC_conc)/(fPOC_conc +  MAOC_conc)) + sqrt(fPOC_d13C_stDev^2 + MAOC_d13C_stDev^2), height = .01), color = "black", inherit.aes = FALSE) +
theme_classic() +
theme(legend.position = "none",
panel.border = element_rect(color = "black",
fill = NA,
size = 1),
# axis.line = element_line(colour = "black",
#                          size = 0),
axis.text=element_text(size = 16),
axis.title=element_text(size = 16),
plot.margin = margin(0, 5, 0, 0, "mm")) + # #top, right, bottom, left
labs(x = expression(paste(delta^{13}, "C (\u2030)")))
return(p)
}
# A function to plot the d14C depth profiles
plot_d14C <- function(df_d14C, df_avg, df_opt, measuredData_soil, color_lines, color_avg, par){
p <- ggplot(df_d14C, aes(x = value, y = depth, colour = variable)) +
geom_path() +
scale_y_continuous(expand = c(0,0), trans = "reverse", sec.axis = sec_axis(~ ., labels = NULL)) +
scale_x_continuous(expand = c(0,0), position = "top", sec.axis = sec_axis(~ ., labels = NULL)) +
coord_cartesian(xlim = c(-500, 200), ylim = c(df_avg$depth[9], 0)) +
scale_colour_manual(labels = unique(df_C$variable),
values = rep(color_lines,length(unique(df_C$variable)))) +
geom_path(data = df_avg, aes(x = avg_d14C, y = depth), size = 2, colour = color_avg) +
geom_point(data = measuredData_soil, aes(x = total_d14C, y = Depth), color = "black") +
# geom_path(data = df_opt, aes(x = opt_d14C, y = depth), size = 2, colour = "black", linetype = "dotted") +
geom_errorbarh(data = measuredData_soil, aes(y = Depth, xmin = ((fPOC_d14C*fPOC_conc +  MAOC_d14C*MAOC_conc)/(fPOC_conc +  MAOC_conc)) - sqrt(fPOC_d14C_stDev^2 + MAOC_d14C_stDev^2), xmax = ((fPOC_d14C*fPOC_conc +  MAOC_d14C*MAOC_conc)/(fPOC_conc +  MAOC_conc)) + sqrt(fPOC_d14C_stDev^2 + MAOC_d14C_stDev^2), height = .01), color = "black", inherit.aes = FALSE) +
theme_classic() +
theme(legend.position = "none",
panel.border = element_rect(color = "black",
fill = NA,
size = 1),
# axis.line = element_line(colour = "black",
#                          size = 0),
axis.text=element_text(size = 16),
axis.title=element_text(size = 16),
plot.margin = margin(0, 5, 0, 0, "mm")) + # #top, right, bottom, left
labs(x = expression(paste(Delta^{14}, "C (\u2030)")))
return(p)
}
# A function to round the error to 2 number after the comma
round2dec <- function(num,dec){
return(round(num*10^dec)/(10^dec))
}
p1 <- plot_C(df_C, df_avg, df_opt, measuredData_soil, color_lines = "deepskyblue3", color_avg = "dodgerblue4", par)
p2 <- plot_d13C(df_d13C, df_avg, df_opt, measuredData_soil, color_lines = "grey75", color_avg = "grey40", par)
p3 <- plot_d14C(df_d14C, df_avg, df_opt, measuredData_soil, color_lines = "grey75", color_avg = "grey40", par)
p1 <- p1 + annotate("label", x = 9.7, y = 0.57, label = "Calibrated for C", hjust = 1, size = 4, fontface = 'italic') +
annotate("text", x = 9.7, y = 0.5, hjust = 1, "label" = paste0("\u03F5\u0304", " = ", round2dec(avgError_OC_Conly,3), " [", round2dec(Q.OC.Conly[1],3), ";", round2dec(Q.OC.Conly[2],3),"]"))
p2 <- p2 + annotate("label", x = -27.9, y = 0.57, label = "Calibrated for C", hjust = 0, size = 4, fontface = 'italic') +
annotate("text", x = -27.9, y = 0.5, hjust = 0, "label" = paste0("\u03F5\u0304", " = ", round2dec(avgError_d13C_Conly,3), " [", round2dec(Q.d13C.Conly[1],3), ";", round2dec(Q.d13C.Conly[2],3),"]"))
p3 <- p3 + annotate("label", x = 180, y = 0.57, label = "Calibrated for C", hjust = 1, size = 4, fontface = 'italic') +
annotate("text", x = 180, y = 0.5, hjust = 1, "label" = paste0("\u03F5\u0304", " = ", round2dec(avgError_d14C_Conly,3), " [", round2dec(Q.d14C.Conly[1],3), ";", round2dec(Q.d14C.Conly[2],3),"]"))
grid.arrange(p1,p2,p3, nrow = 1)
source("~/Documents/ETH/Papers/14. d13C model/7. Documents submitted to BG/SOILcarb R - July 2024/Main_script.R", echo=TRUE)
out <- plotting(res, d13C, d14C, par)
# The plots for litter C
pl1 <- out[[1]]
pl2 <- out[[2]]
pl3 <- out[[3]]
out <- plotting(res, d13C, d14C, par)
# The plots for litter C
pl1 <- out[[1]]
pl2 <- out[[2]]
pl3 <- out[[3]]
quartz(title = "litter carbon", width = 8, height = 5)
ggarrange(pl1, pl2, pl3, nrow = 3, labels = c("(A)", "(B)", "(C)"), font.label=list(color="black",size=12))
pc1 <- out[[4]]
pc2 <- out[[5]]
pc3 <- out[[6]]
quartz(title = "Depth profiles", width = 16*0.39, height = 7*0.39)
ggarrange(pc1,pc2,pc3, nrow = 1, labels = c("(A)", "(B)", "(C)"), font.label=list(color="black",size=12))
source("~/Documents/ETH/Papers/14. d13C model/7. Documents submitted to BG/SOILcarb R - July 2024/Main_script.R", echo=TRUE)
source("~/Documents/ETH/Papers/14. d13C model/7. Documents submitted to BG/SOILcarb R - July 2024/Main_script.R", echo=TRUE)
# quartz(title = "litter carbon", width = 8, height = 5)
ggarrange(pl1, pl2, pl3, nrow = 3, labels = c("(A)", "(B)", "(C)"), font.label=list(color="black",size=12))
source("~/Documents/ETH/Papers/14. d13C model/7. Documents submitted to BG/SOILcarb R - July 2024/Main_script.R", echo=TRUE)
